import router from '../../router/index'

const _import = require('@/router/_import_' + process.env.NODE_ENV)

function menuMachining(data) {
  for (let i = 0; data.length > i; i++) {
    try {
      if (data[i].children.length > 0) {
        data[i].children = menuMachining(data[i].children)
      }
    } catch (e) {
    }
    if (data[i]['components']) {
      if (data[i]['components'].header) {
        data[i]['components'].header = _import(data[i]['components'].header)
      }
      if (data[i]['components'].content) {
        data[i]['components'].content = _import(data[i]['components'].content)
      }
    }
    if (data[i]['component']) {
      data[i]['component'] = _import(data[i]['component'])
    }
  }
  return data
}

export default function () {
  let menuData = JSON.parse(arguments[0])
  let newsMenu = menuMachining(menuData)
  newsMenu.push(
    {
      path: '/123',
      name: '123',
      components: {
        content: _import('HelloWorld'),
        header: _import('header/header')
      }
    }
  )
  console.info(newsMenu)
  router.addRoutes(
    newsMenu
  )
}
